<?php

namespace App\Models\Common;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Link extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $fillable = [
        'title', 'link',
    ];

    public function log() : HasMany
    {
        return $this->hasMany(LinkLog::class, 'link_id');
    }

    public function pv()
    {
        return $this->log()->count('id');
    }

    public function uv()
    {
        return $this->log()->select('day', 'ip')->distinct()->get()->count();
    }
}
